package com.appsindy.reserv.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.appsindy.common.action.AppsindyBaseAction;
import com.appsindy.common.util.DateUtils;
import com.appsindy.reserv.dao.ReportDAO;
import com.appsindy.reserv.dao.ShiftControlDAO;
import com.appsindy.reserv.vo.ReserveReportVO;
import com.appsindy.reserv.vo.ShiftTransVO;

public class ReportAction extends AppsindyBaseAction {

	private ShiftTransVO shiftTrx;
	private List<ShiftTransVO> shiftTrxList;
	private Date shiftDate;
	
	private List<ReserveReportVO> reservationList;
	private Date startDate;
	private Date endDate;
	
	private ShiftControlDAO shiftControlDAO;
	private ReportDAO reportDAO;
	
	public String execute(){
		
		return SUCCESS;
	}
	
	public String shiftTrx(){
		if(getStartDate() == null){
			setStartDate(new Date());
		}
		if(getEndDate() == null){
			setEndDate(new Date());
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("startDate", DateUtils.getSqlDateStr(getStartDate()));
		params.put("endDate", DateUtils.getSqlDateStr(getEndDate()));
		
		//List<ShiftTransVO> list = getShiftControlDAO().getShiftTrxByDate(DateUtils.getSqlDateStr(getShiftDate()));
		List<ShiftTransVO> list = getShiftControlDAO().getShiftTrxByDate(params);
		if(list != null && list.size() > 0){
			setShiftTrx(list.get(0));
		} else{
			setShiftTrx(new ShiftTransVO());
			list = new ArrayList<ShiftTransVO>();
		}
		log.info("Data on Date " + shiftDate + " = " + list.size() + " rows");
		setShiftTrxList(list);
		return "shiftTrx";
	}
	
	public String reserveDetail(){
		if(getStartDate() == null){
			setStartDate(new Date());
		}
		if(getEndDate() == null){
			setEndDate(new Date());
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("startDate", DateUtils.getSqlDateStr(getStartDate()));
		params.put("endDate", DateUtils.getSqlDateStr(getEndDate()));
		
		List<ReserveReportVO> list = getReportDAO().getReservationDetailByDate(params);
		if(list != null && list.size() > 0){
			setReservationList(list);
		} else{
			setReservationList(new ArrayList<ReserveReportVO>());
		}
		return "reserveDetail";
	}
	
	public void setShiftControlDAO(ShiftControlDAO shiftControlDAO){
		this.shiftControlDAO = shiftControlDAO;
	}
	public ShiftControlDAO getShiftControlDAO(){
		return shiftControlDAO;
	}

	public ReportDAO getReportDAO() {
		return reportDAO;
	}
	public void setReportDAO(ReportDAO reportDAO) {
		this.reportDAO = reportDAO;
	}
	
	public ShiftTransVO getShiftTrx() {
		return shiftTrx;
	}
	public void setShiftTrx(ShiftTransVO shiftTrx) {
		this.shiftTrx = shiftTrx;
	}

	public List<ShiftTransVO> getShiftTrxList() {
		return shiftTrxList;
	}
	public void setShiftTrxList(List<ShiftTransVO> shiftTrxList) {
		this.shiftTrxList = shiftTrxList;
	}

	public Date getShiftDate() {
		return shiftDate;
	}
	public void setShiftDate(Date shiftDate) {
		this.shiftDate = shiftDate;
	}
	
	public List<ReserveReportVO> getReservationList() {
		return reservationList;
	}
	public void setReservationList(List<ReserveReportVO> reservationList) {
		this.reservationList = reservationList;
	}

	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
}
